<%@page import="com.wanmait.hotelManage.vo.RoomType"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.wanmait.hotelManage.vo.Pager"%>
<%@page import="java.util.List"%>
<%@page import="com.wanmait.hotelManage.vo.Room"%>
    <%
    String path=request.getContextPath();
    List<Room> rooms=(List<Room>)request.getAttribute("rooms");
    List<RoomType> roomtypes=(List<RoomType>)request.getAttribute("roomtypes");
    %>
<jsp:include page="/manage/inc/header.jsp"></jsp:include>
   <jsp:include page="/manage/inc/menu.jsp"></jsp:include>
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="<%=path%>/manage/index.jsp">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">客房管理</span></div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="<%=path%>/manage/RoomTypeServlet?action=beforeinsert"><i class="icon-font"></i>新增作品</a>
                        <a id="batchDel" href="javascript:void(0)"><i class="icon-font"></i>批量删除</a>
                           <span id="divSelect">
                               房型： <select name="colId" id="catid" class="required">
                              <option value="0">全部</option>
                                <%
                                if(roomtypes!=null){
                                	for(int i=0;i<roomtypes.size();i++){
                                		RoomType roomtype=roomtypes.get(i);
                                		%>
                                		<option value="<%=roomtype.getId()%>"><%=roomtype.getTitle() %></option>
                                		<%
                                	}
                                }
                                %>
                                    
                                </select>
                               状态： <select name="check" id="check" class="required">
                              <option value="0">全部</option>
                                 <option value="1">入住</option>
                                     <option value="2">空闲</option>
                                </select>
                        <input class="btn btn-primary btn6 mr10" id="search" value="搜索" type="button">
                    </span>
                    <span id="roomtypeid">
                    房间号：<input type="text" size="5" id="textid">
                     <input class="btn btn-primary btn6 mr10" id="roomtype" value="搜索" type="button"><span id="spanroomtype"></span>
                     </span>
                    </div>
                </div>
                <div class="result-content">
                
                <div id="bbb">  
                <div id="pagediv">               
                    
                    <table class="result-tab" width="100%">
                        <tr>
                            <th class="tc" width="5%"><input class="allChoose" name="" type="checkbox"></th>
                            <th>序号</th>
                            <th>客房号</th>
                            <th>标题</th>
                            <th>价格</th>
                            <th>折扣价格</th>
                            <th>状态</th>
                            <th>入住人员信息详情</th>
                            <th>操作</th>
                        </tr>
                        
                        <%
                        if(rooms!=null){
                        	for(int i=0;i<rooms.size();i++){
                        		Room room=rooms.get(i);
                        	
                        	%>
                        	<tr id="tr<%=room.getId()%>">
                            <td class="tc"><input data-id="<%=room.getId() %>" class="choose" name="id[]" value="59" type="checkbox"></td>
                            <td><%=i+1 %></td>
                            <td><%=room.getNumber() %></td>
                            <td><%=room.getRoomtype().getTitle() %></td>
                            <td><%=room.getRoomtype().getPrice() %></td>
                            <td><%=room.getRoomtype().getDiscountPrice() %></td>
                            <td class="check"><span class="checkin"><%=room.getCheckIn() %></span></td>
                            <td style="width:150px;"><a href="<%=path%>/manage/RoomServlet?action=checkinInformation&id=<%=room.getId()%>">显示信息</a></td>
                            <td>
                                <a class="link-update" href="<%=path%>/manage/RoomServlet?action=beforeupdate&id=<%=room.getId()%>">修改</a>
                                <a id="de<%=room.getId() %>" class="link-del" href="javascript:void(0)">删除</a>
                            </td>
                        </tr>
                        	<%
                        }
                        }
                        %>
                    </table>
                    
                    
                    <div class="qwe">
                    <%
                    Pager pager=(Pager)request.getAttribute("pager");
                    if(pager!=null){
                    	 int start= 1;
                         int end =pager.getPageCount();
                         if(pager.getPageCount()>5){
                        	 start=pager.getPageNo()-2<1?1:pager.getPageNo()-2;
                        	 end=start+4;
                        	 if(end>pager.getPageCount()){
                        		 end=pager.getPageCount();
                        		 start=end-4;
                        	 }
                         }
                         %>
                         [<a class="ok" href="javascript:void(0)">上一页</a>]
                         <%
                    	for(int i=start;i<=end;i++){
                    		%>
                    		[<a class="number" href="javascript:void(0)"><%=i %></a>]
                    		<%
                    	}
                         %>
                         [<a class="no" href="javascript:void(0)">下一页</a>]
                         <%
                    }
                    %>
                    </div>
                    </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!--/main-->
</div>
<jsp:include page="/manage/inc/footer.jsp"></jsp:include>
<style>
.qwe{
text-align:center;
}
#roomtypeid{
margin-left:100px;
}
</style>
<script>
$(function(){
	$("#bbb").on("click",".link-del",function(){
		if(!window.confirm("你确定要删除吗")){
			return false;
		}
		var id=$(this).attr("id").substring(2);
		$.get("<%=path%>/manage/RoomServlet?action=del",
				{id:id},
				function(){
					$("#tr"+id).remove();
				}
				)
	})
	$("#bbb").on("click",".allChoose",function(){
		$(".choose").prop("checked",$(this).prop("checked"))
	})
	$("#batchDel").click(function(){
		var ids=[];
		$(".choose:checked").each(function(){
			var id=$(this).data("id");
			ids.push(id);
		});
		if(ids.length>0){
			$.get("<%=path%>/manage/RoomServlet?action=dele",
					{id:ids.toString(),pageNo:<%=pager.getPageNo()%>},
					function(){
						for(var i=0;i<ids.length;i++){
							$("#tr"+ids[i]).remove();
						}
					}
					)
				}
	})
	$(".checkin").each(function(){
		var check=$(this).html();
		
		if(check=="false"){
			$(this).html("空闲");
		}else if(check=="true"){
			$(this).html("入住");
		} 
	})
	$(".no").click(function(){
							/* $(".number").css("color","black");
							$(this).css("color","red"); */
							var content=<%=pager.getPageNo()%>;
							if(content<<%=pager.getPageCount()%>){
								content++;
							}
							$.ajax({
								url:"<%=path%>/manage/RoomServlet?action=inittwo",
									data:{pageNo:content},
										success:function(msg){
											$("#pagediv").html(msg);
										}
							})
						})
	$(".ok").click(function(){
		/* $(".number").css("color","black");
		$(this).css("color","red"); */
		var content=<%=pager.getPageNo()%>;
		if(content>1){
			content--;
		}
		$.ajax({
			url:"<%=path%>/manage/RoomServlet?action=inittwo",
				data:{pageNo:content},
					success:function(msg){
						$("#pagediv").html(msg);
					}
		})
	})
	$(".number").click(function(){
		var content=$(this).html();
		$.ajax({
			url:"<%=path%>/manage/RoomServlet?action=inittwo",
			data:{pageNo:content},
			success:function(msg){
				$("#pagediv").html(msg);
			}
		})
		
	})
})

</script>
<style>
#divSelect{
margin-left:100px;
}
</style>
<script>
$(function(){
	$("#myform").on("click","#search",function(){
		var catid=$("#catid").val();
		var check=$("#check").val();		
		$.ajax({
			url:"<%=path%>/manage/RoomServlet?action=search",
				data:{catid:catid,check:check},
					success:function(mag){
							$("#bbb").html(mag);
						}
		})
	})
	$("#myform").on("click","#roomtype",function(){
		var id=$("#textid").val();
		if(id.length>0){
			$("#spanroomtype").html("");
		$.ajax({
			url:"<%=path%>/manage/RoomServlet?action=number",
				data:{id:id},
					success:function(mag){
							$("#bbb").html(mag);
						}
		})
		}else{
			$("#spanroomtype").html("不能为空");
		}
	})
})
</script>
